﻿using System;
using System.Web;
using System.Web.SessionState;
using SE6;
using System.Text;
/// <summary>
///界面层对象，负责部分界面生成
/// </summary>
public enum PageClass
{
	Default,//首页
	Login,//登录页面
	Register,//注册页面
	ResetPassword,//重设密码第一步页面
	MyArchives,//我的档案
	DetailArchive,//档案详细信息
	DetailProfile,//用户详细信息
	UserManager,//用户管理
	SystemManager,//系统管理
	LeaveMessage,//留言吧
	UploadArchive,//上传档案
	DetailTopics,//浏览回复
	Result,//结果页面
	ResetPassword2,//重设密码第2步
}
public static class GUI
{	
	//根据不同用户类型以及页面生成不同导航菜单
	public static String NavMenu(PageClass curClass)
	{
		System.Text.StringBuilder sbNav = new System.Text.StringBuilder();
		SE6.User curUsr=SessionMan.GetLoginUser();
		if (curClass!=PageClass.Default)
			sbNav.Append("<ul class='clearFix'><li><a href='Default.aspx'>首页</a></li>");			
		else
			sbNav.Append("<ul class='clearFix'><li class='cue' href='Default.aspx'>首页</li>");
		if (curUsr == null)
		{
			if (curClass!=PageClass.Login)
				sbNav.Append("<li><a href='Login.aspx'>登录</a></li>");
			else
				sbNav.Append("<li class='cue'>登录</li>");
			if (curClass!=PageClass.Register)
				sbNav.Append("<li><a href='Register.aspx'>注册</a></li>");
			else
				sbNav.Append("<li class='cue'>注册</li>");
			if (curClass!=PageClass.ResetPassword)
				sbNav.Append("<li><a href='ForgetCode.aspx'>忘记密码</a></li>");
			else
				sbNav.Append("<li class='cue'>忘记密码</li>");
			if (curClass == PageClass.DetailTopics)
			{
				sbNav.Append("<li><a href='LeaveMsg.aspx'>返回留言吧</a></li>");
				sbNav.Append("<li class='cue'>浏览帖子</li>");
			}
			else if (curClass!=PageClass.LeaveMessage)
				sbNav.Append("<li><a href='LeaveMsg.aspx'>我要留言</a></li>");
			else
				sbNav.Append("<li class='cue'>留言吧</li>");
			if (curClass == PageClass.DetailProfile)
				sbNav.Append("<li class='cue'>用户信息中心</li>");
			if (curClass==PageClass.Result)
				sbNav.Append("<li class='cue'>结果反馈</li>");
			if (curClass==PageClass.ResetPassword2)
				sbNav.Append("<li class='cue'>重设您的密码</li>");
		}
		else
		{
			if (curClass!=PageClass.DetailProfile)
				sbNav.Append(
					"<li><a href='DetailProfile.aspx?id=" + curUsr.ID + "'>我的信息</a></li>");
			else
				sbNav.Append(
					"<li class='cue'>个人信息</li>");
			if (curClass!=PageClass.MyArchives)
				sbNav.Append("<li><a href='MyArchives.aspx?id=" + curUsr.ID + "'>我的档案</a></li>");
			else
				sbNav.Append("<li class='cue' >我的档案</li>");
			if (curClass!=PageClass.UploadArchive)
				sbNav.Append("<li><a href='UploadAr.aspx'>上传档案</a></li>");
			else
				sbNav.Append("<li class='cue'>上传档案</li>");
			if (curUsr.IsUserManager())
			{
				if (curClass!=PageClass.UserManager)
					sbNav.Append("<li><a href='UsersManager.aspx?cp=0'>用户管理</a></li>");
				else
					sbNav.Append("<li class='cue'>用户管理</li>");
			}
			if (curUsr.IsSystemManager())
			{
				if (curClass!=PageClass.SystemManager)
					sbNav.Append("<li><a href='SystemManager.aspx?id=" + curUsr.ID + "'>系统管理</a></li>");
				else
					sbNav.Append("<li class='cue'>系统管理</li>");
			}
			if (curClass == PageClass.DetailTopics)
			{
				sbNav.Append("<li><a href='LeaveMsg.aspx'>返回留言吧</a></li>");
				sbNav.Append("<li class='cue'>"+
					(curUsr.IsLeaveWordManager() ? "帖子管理" : "浏览帖子")+"</li>");
			}
			else if (curClass!=PageClass.LeaveMessage)
				sbNav.Append("<li><a href='LeaveMsg.aspx'>"+
					(curUsr.IsLeaveWordManager() ? "留言管理" : "我要留言")+"</a></li>");
			else
				sbNav.Append("<li class='cue' >" +
					(curUsr.IsLeaveWordManager() ? "留言管理" : "我要留言")+"</li>");
			sbNav.Append("<li><a href='par.aspx?t=1'>安全退出</a></li>");
			if (curClass == PageClass.Result)
				sbNav.Append("<li class='cue'>结果反馈</li>");
			if (curClass == PageClass.ResetPassword2)
				sbNav.Append("<li class='cue'>重设您的密码</li>");
		}
		sbNav.Append("</ul>");
		return sbNav.ToString();
	}
	//根据canUpdate生成可编辑字段或只读字段
	public static String SmartText(Boolean canUpdate,String id,Object curValue)
	{
		if (canUpdate)
			return "*<input type='text' id='" + id + "' name='" + id + "' readonly='readonly'" +
							" class='readMode' ondblclick='CE(this);'  onblur='CR(this);' value='" + curValue.ToString()
							+ "'/>";
		else
			return curValue.ToString();
	}
	public static String SmartSubmit(Boolean canUpdate,Int32 id)
	{
		return (canUpdate ? ("<input type='hidden' id='id' name='id' value='" + id + "' />" +
			"<div><input id='sm' type='submit' value='提交更改' class='button' /></div>") : "");
	}
	public static String SmartCheckBox(Boolean isChecked,String id,String label)
	{
		return "<input type='checkbox' id='" + id + "' name='" + id + "' " + (isChecked ? "checked='checked'" : "") + "/>" +
			"<label for='"+id+"'>"+label+"</label>";
	}
}
